import java.awt.event.*;
import javax.swing.*;
public class ListenGuess implements ActionListener { 
   RandomNumber randomNumber;
   JTextField inputGuess;  
   JTextField hintText; 
   public void setRandomNumber(RandomNumber randomNumber) {
      this.randomNumber=randomNumber;
   }
   public void setHintJTextField(JTextField t){
      hintText=t; 
   }
   public void setInputJTextField(JTextField t){
      inputGuess=t; 
   }
   public void actionPerformed(ActionEvent e) {
      int guess=0;
      try { guess=Integer.parseInt(inputGuess.getText());
            if(guess==randomNumber.getNumber()) {
               hintText.setText(guess+":猜对了！");
            }
            else if(guess>randomNumber.getNumber()) {
               hintText.setText(guess+":猜大了！");
            }
            else if(guess<randomNumber.getNumber()) {
               hintText.setText(guess+":猜小了！");
            }
            inputGuess.setText(null); 
       }
       catch(NumberFormatException event) {
            hintText.setText("请输入数字字符");
       } 
   }
}

